OpenCASCADE DataExchange DWG

您所在的位置:网站首页 Js 加载dwg OpenCASCADE DataExchange DWG

OpenCASCADE DataExchange DWG

#OpenCASCADE DataExchange DWG| 来源: 网络整理| 查看: 265

OpenCASCADE DataExchange DWG

[email protected]

Abstract. DWG is a file format created in the 70’s for the emerging CAD applications. Currently it is the native file format of AutoCAD, a proprietary CAD program developed by Autodesk. Libredwg is a free C library to read and write DWG files. This program is part of GNU project, released under the aegis of GNU. The paper focus on the usage of Libredwg, and use the Libredwg to read a DWG file and output the entities of the DWG to Tcl script for OpenCASCADE Draw Test Harness visualization. 

Key Words. OpenCASCADE, DWG, Libredwg, DataExchange, Windows 

1. Introduction

DWG是CAD软件AutoCAD及基于AutoCAD的软件保存设计数据所用的一种专有文件格式,始于1970年代的一套Interact CAD软件。之后Autodesk公司于1982年取得版权开始使用这种文件格式。Autodesk公司拥有、开发并且更新DWG文件格式,通常每隔几年DWG就会随着在AutoCAD中添加新的特性而对DWG格式进行更新。 

DWG格式及它的ASCII格式变体DXF格式,已经成为CAD制图数据交换中的事实文件标准,据估计全世界有超过十亿个DWG文件。有几家公司正在对DWG文件格式进行逆向工程以试图为其它的设计软件提供读写DWG文件的能力。Autodesk公司也提供了一套需要授权的DWG读写技术开发包“RealDWG”。 

新版的AutoCAD可以打开旧版的DWG文件,AutoCAD2007可以打开2.0版本的DWG文件并且可以保存为R14版本。另外Autodesk公司提供一个免费的DWG查看工个“DWG TrueView”用于查看所有版本的DWG文件。另外Autodesk公司是vendor lock-in策略的强力支持者,尽力保护DWG文件格式并且禁止开发支持DWG格式的开放源代码库。 

2006年11月12日,Autodesk公司对Open Design Alliance-一款支持DWG格式的自由库OpenDWG提出了诉讼。 

ASCII格式的DXF文件的文档Autodesk提供了,但是二进制的DWG格式并没有提供相关文档,由上可见对DWG文件的读写处理是非常困难的。本文主要介绍如何使用Libredwg库来对读取DWG中的几何数据,并将几何数据生成为可以在OpenCASCADE中显示的Tcl脚本,以验证读取数据的正确性。 

2.Modify Libredwg for Visual Studio

Libredwg是一个Free的读写DWG文件的C库,这个程序是GNU项目的一部分,授权方式是GNU GPL3。 

Libredwg是Libdwg的一个分支,其目的是创建OpenDWG库的一个替代库。也是高优先级的Free软件项目: 

http://www.fsf.org/campaigns/priority-projects/priority-projects/highpriorityprojects#ReplaceOpenDWG ,更多信息可访问http://www.gnu.org/software/libredwg 。 

从网上下载的Libredwg源程序是在Linux下编译的,并没有配置在Windows下编译方法。为了使用Libredwg可以在Windows上的Visual Studio中编译通过,对Libredwg做了一些修改,最终编译成功。在Visual Studio 2008上成功编译的工程可以文后的链接中下载。 

下面给出使用Libredwg读取DWG文件中直线、圆及文字的例子程序: 

/* * load_dwg.c: load a DWG, get lines, text and circles * written by Felipe Castro * modified by Felipe Corrêa da Silva Sances * modified by Thien-Thi Nguyen */ #include #include "suffix.c" void add_line(double x1, double y1, double x2, double y2) { // Make something with that } void add_circle(double x, double y, double R) { // Make something with that } void add_text(double x, double y, char *txt) { // Make something with that } int load_dwg(char *filename) { unsigned int i; int success; Dwg_Data dwg; dwg.num_objects = 0; success = dwg_read_file(filename, &dwg); for (i = 0; i < dwg.num_objects; i++) { Dwg_Entity_LINE *line; Dwg_Entity_CIRCLE *circle; Dwg_Entity_TEXT *text; switch (dwg.object[i].type) { case DWG_TYPE_LINE: line = dwg.object[i].tio.entity->tio.LINE; add_line(line->start.x, line->end.x, line->start.y, line->end.y); break; case DWG_TYPE_CIRCLE: circle = dwg.object[i].tio.entity->tio.CIRCLE; add_circle(circle->center.x, circle->center.y, circle->radius); break; case DWG_TYPE_TEXT: text = dwg.object[i].tio.entity->tio.TEXT; add_text(text->insertion_pt.x, text->insertion_pt.y, text->text_value); break; } } dwg_free(&dwg); return success; } int main (int argc, char *argv[]) { REQUIRE_INPUT_FILE_ARG (argc); load_dwg (argv[1]); return 0; }

因为Libredwg用的C编程风格,没有定义导出定义宏,所以决定将Libredwg编译成静态库libredwg.lib,然后使用其头文件及这个静态库的方式来在程序中使用Libredwg库。 

经过测试,若DWG中只有简单的线和圆等简单实体,Libredwg还是可以正确读取出。但是若用rewrite的例子来测试写DWG的功能,简单的实例如一个圆的数据都会写出到DWG失败,看样子写的功能还没有完全实现好。 

3.DWG to OCC

基于上面的例子程序,结合Libredwg的读取功能,将DWG中的几何数据导出成Tcl脚本,这样就可以方便在OpenCASCADE的Draw Test Harness中来测试结果了。下面给出具体的程序实例及如何在Draw Test Harness中来使用生成的Tcl脚本。 

/* * Copyright (c) 2014 eryar All Rights Reserved. * * File : Main.cpp * Author : [email protected] * Date : 2014-10-15 20:46 * Version : 1.0v * * Description : Use libredwg to read data from DWG and * output them to Tcl script for Draw. * * Key words : OpenCASCADE, libredwg, Draw Test Harness */ #include "dwg.h" #include #include #pragma comment(lib, "../Debug/libredwg.lib") // Output the entities to Tcl for OpenCASCADE Draw. static std::ofstream theTclExporter("d:/dwg2occ.tcl"); void OutputLine(int id, const Dwg_Entity_LINE* theLine) { // Draw Tcl command: vline name xa ya za xb yb zb theTclExporter tio.TEXT); break; } } return aResult; } int main(int argc, char* argv[]) { theTclExporter.flags(std::ios::fixed); theTclExporter


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3